<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Payhistory extends AdminController{
	public $_validation = null;
	
	function __construct(){
		parent::__construct();
		$this->load->model('MPayHistory');
		$this->_validation = Array(
			array('field'=>'finance_id', 'label'=>'财务', 'rules'=>'required|integer|max_length[11]')
            ,array('field'=>'pay_request_id', 'label'=>'所属打款申请记录', 'rules'=>'integer|max_length[11]')
            ,array('field'=>'task_operate_id', 'label'=>'所属测评记录', 'rules'=>'integer|max_length[11]')
			,array('field'=>'pay_amount', 'label'=>'付款总额', 'rules'=>'required')
			,array('field'=>'pay_account', 'label'=>'付款账户', 'rules'=>'required')
			,array('field'=>'receive_account', 'label'=>'收款账户', 'rules'=>'required')
			,array('field'=>'remark', 'label'=>'备注', 'rules'=>'max_length[255]')
			,array('field'=>'update_time', 'label'=>'更新时间', 'rules'=>'')
		);
	}

	function index(){
		//$this->output->enable_profiler(TRUE);
		$this->load->library('FormFilter');
		$this->load->helper('formfilter');
		$this->formfilter->addFilter('finance_id', 'where');
		$this->formfilter->addFilter('pay_account','where');
		$this->formfilter->addFilter('receive_account','where');

        if($begintime = filterValue('finance_his_create_time_begin')){
            $this->formfilter->addFilter('finance_his_create_time_begin', 'where',array('create_time >= ',strtotime($begintime.' 00:00:00')));
        }
        if($endtime = filterValue('finance_his_create_time_end')){
            $this->formfilter->addFilter('finance_his_create_time_end', 'where',array('create_time <= ',strtotime($endtime.' 23:59:59')));
        }


        $number_perpage = filterValue('payhistory_number_perpage');
        $total_number = $this->MPayHistory->getCount();
        $limit = $this->pagination($total_number,'',$number_perpage);
        $list = $this->MPayHistory->getList($limit);
        $this->assign('total_number', $total_number);

        $this->load->model('MAdmin');
        $this->load->model('MPayAccount');
        $allFinance = $this->MAdmin->getAllFanceAdmin();
        $allAccount = $this->MPayAccount->getAllAvailableAccount();

        $this->assign('allFinance', $allFinance);
        $this->assign('allAccount', $allAccount);
		$this->assign('list', $list);
		$this->layout();
	}
}
